package org.ktpro.shortlink.project.service.impl;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.ktpro.shortlink.project.service.UrlTitleService;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * 短链接标题功能实现类
 *
 * @Author Kris20030907
 * QQ: 3185633428 微信: 18712679036
 */
@Service
public class UrlTitleServiceImpl implements UrlTitleService {

    /**
     * 获取网页title
     */
    @Override
    public String getTitleByUrl(String url) {
        String title = null;
        try {
            Document document = Jsoup.connect(url).get();
            // 获取网页标题
            title = document.title();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return title;
    }
}
